home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 201-225 / disk_222 / plplot / src / source.zoo / plot3d.c < prev    next >
C/C++ Source or Header  |  1989-05-15  |  4KB  |  113 lines

  1. /* Plots a 3-d representation of the function z[x][y]. The x values */
  2. /* are stored as x[0..nx-1], the y values as y[0..ny-1], and the */
  3. /* z values are in the 2-d array z[][0..ly-1]. The integer "opt" */
  4. /* specifies: */
  5. /*  opt = 1:  Draw lines parallel to x-axis */
  6. /*  opt = 2:  Draw lines parallel to y-axis */
  7. /*  opt = 3:  Draw lines parallel to both axes */
  8.  
  9. /* "work" is an integer work array of size at least 4*max(nx,ny) */
  10.  
  11. #include "plplot.h"
  12. #include <math.h>
  13.  
  14. void plot3d(x,y,z,work,ly,nx,ny,opt)
  15. int ly, nx, ny, opt;
  16. float x[],y[],*z;
  17. int work[];
  18. {
  19.       int b;
  20.       float cxx, cxy, cyx, cyy, cyz;
  21.  
  22.       int init;
  23.       int i, ix, iy;
  24.  
  25.       int level;
  26.       glev(&level);
  27.       if (level < 3) fatal("Please set up window before calling PLOT3D");
  28.  
  29.       if (opt<1 || opt>3) fatal("Bad option in PLOT3D");
  30.       if (nx<=0 || ny<=0 || ly<ny) fatal("Bad array dimensions in PLOT3D.");
  31.  
  32. /* Check that points in x and in y are strictly increasing */
  33.  
  34.       for (i=0; i<nx-1; i++)
  35.         if (x[i]>=x[i+1]) fatal("X(*) must be strictly increasing in PLOT3D");
  36.  
  37.       for (i=0; i<ny-1; i++)
  38.         if (y[i]>=y[i+1]) fatal("Y(*) must be strictly increasing in PLOT3D");
  39.  
  40.       b = 2*max(nx,ny)+1;
  41.       gw3wc(&cxx,&cxy,&cyx,&cyy,&cyz);
  42.       init = 1;
  43.       
  44.       if (cxx >= 0.0 && cxy <= 0.0) {
  45.         if (opt != 2) {
  46.           for (iy=2; iy<=ny; iy++)  {
  47.             plt3zz(1,iy,1,-1,-opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  48.             init = 0;
  49.           }
  50.         }
  51.         else  {
  52.           plt3zz(1,ny,1,-1,-opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  53.           init = 0;
  54.         }
  55.         if (opt != 1) 
  56.           for (ix=1; ix<=nx-1; ix++)
  57.             plt3zz(ix,ny,1,-1,opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  58.         else
  59.           plt3zz(1,ny,1,-1,opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  60.       }
  61.       else if (cxx <= 0.0 && cxy <= 0.0) {
  62.         if (opt != 1) {
  63.           for (ix=2; ix<=nx; ix++) {
  64.             plt3zz(ix,ny,-1,-1,opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  65.             init = 0;
  66.           }
  67.         }
  68.         else  {
  69.           plt3zz(nx,ny,-1,-1,opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  70.           init = 0;
  71.         }
  72.         if (opt != 2) 
  73.           for (iy=ny; iy>=2; iy--)
  74.             plt3zz(nx,iy,-1,-1,-opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  75.         else
  76.           plt3zz(nx,ny,-1,-1,-opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  77.       }
  78.       else if (cxx <= 0.0 && cxy >= 0.0) {
  79.         if (opt != 2) {
  80.           for (iy=ny-1; iy>=1; iy--) {
  81.             plt3zz(nx,iy,-1,1,-opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  82.             init = 0;
  83.           }
  84.         }
  85.         else {
  86.           plt3zz(nx,1,-1,1,-opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  87.           init = 0;
  88.         }
  89.         if (opt != 1)
  90.           for (ix=nx; ix>=2; ix--)
  91.             plt3zz(ix,1,-1,1,opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  92.         else
  93.           plt3zz(nx,1,-1,1,opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  94.       }
  95.       else if (cxx >= 0.0 && cxy >= 0.0) {
  96.         if (opt != 1) {
  97.           for (ix=nx-1; ix>=1; ix--) {
  98.             plt3zz(ix,1,1,1,opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  99.             init = 0;
  100.           }
  101.         }
  102.         else  {
  103.           plt3zz(1,1,1,1,opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  104.           init = 0;
  105.         }
  106.         if (opt != 2)
  107.           for (iy=1; iy<=ny-1; iy++)
  108.             plt3zz(1,iy,1,1,-opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  109.         else
  110.           plt3zz(1,1,1,1,-opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  111.       }      
  112. }
  113.